@Inject('$log', '$state')
class GlobalParamsController {
  constructor() {
    const $injector = angular.element(document).injector();
    const globalService = $injector.get('globalService');
    const $rootScope = $injector.get('$rootScope');
    const orgId = $rootScope.orgId || '0ed5e18dafa24e3c84a81814745804fd';
    const globalDocumentService = $injector.get('documentService');

    /*eslint-disable */
    if (!$rootScope.positionParams) {
      globalService
        .queryPost({
          mapParams: {
            orgId
          }
        })
        .then((res) => {
          $rootScope.positionParams = res.rows;
        });
    }
    if (!$rootScope.deptParams) {
      globalService
        .queryDept({
          mapParams: {
            orgId
          }
        })
        .then((res) => {
          $rootScope.deptParams = res.rows;
        });
    }
    if (!$rootScope.deviceCategoryParams) {
      globalService
        .queryDeviceCategory({
          mapParams: {
            orgId
          }
        })
        .then((res) => {
          $rootScope.deviceCategoryParams = res.rows;
        });
    }
    if (!$rootScope.queryDeviceUsedLocation) {
      globalService
        .queryDeviceUsedLocation({
          mapParams: {
            orgId
          }
        })
        .then((res) => {
          $rootScope.deviceUsedLocationParams = res.rows;
        });
    }
    if (!$rootScope.dics) {
      globalService
        .querySystemDicByType('部门类别')
        .then((res) => {
          $rootScope.dics = res.rows;
        })
    }
    if (!$rootScope.degreeParams) {
      globalService
        .querySystemDicByType('学历')
        .then((res) => {
          $rootScope.degreeParams = res.rows;
        })
    }
    if (!$rootScope.workerTypeParams) {
      globalService
        .querySystemDicByType('人员种类')
        .then((res) => {
          $rootScope.workerTypeParams = res.rows;
        })
    }
    // if (!$rootScope.deviceTypeParams) {
    //   globalService
    //     .querySystemDicByType('设备分类')
    //     .then((res) => {
    //       $rootScope.deviceTypeParams = res.rows;
    //       this.deviceTypeParams = res.rows;
    //     })
    // }
    globalService
      .querySystemDicByType('设备分类')
      .then((res) => {
        $rootScope.deviceTypeParams = res.rows;
        this.deviceTypeParams = res.rows;
      })
    if (!$rootScope.causeAnalysisParams) {
      globalService
        .querySystemDicByType('原因分析')
        .then((res) => {
          $rootScope.causeAnalysisParams = res.rows;
        })
    }

    // 资料类型
    if (!$rootScope.documentType) {
      globalDocumentService
        .getBoxes($rootScope.orgId)
        .then((res) => {
          $rootScope.documentType = res.rows;
        });
    }

    this.getDeviceCategory();
  }

  /*eslint-disable */
  getDeviceCategory(type) {
    if (this.deviceTypeParams) {
      this.deviceTypeParams.forEach((item) => {
        if (item.value === type) {
          this.deviceName = item.name;
        }
      });
      return this.deviceName;
    }
  }

  getDeviceCheckResult(value) {
    switch (value) {
      case '1':
        return '合格';
        break;
      case '2':
        return '不合格';
        break;
      default:
        break;
    }
  }

  getDownloadSrc(id) {
    return `/sgms/api/v1/common/downLoad/${id}`;
  }

}

export default GlobalParamsController;
